/**
 * 
 */
package nc.tb.analyse.ui;

import java.awt.Container;
import java.util.ArrayList;
import java.util.HashMap;

import nc.tb.cube.CubeView;
import nc.tb.cube.DimLayout;
import nc.tb.cube.model.MetaPlan;
import nc.tb.dim.DimDef;
import nc.tb.dim.DimMember;
import nc.tb.pub.IDimType;

/**
 * @author zhangliangf
 *
 */
public class CompileQueryDlg extends AbstractQueryDlg {
	public CompileQueryDlg(Container parent, MetaPlan cube, HashMap<DimDef, ArrayList<DimMember>> dimConditions){
		super(parent, cube, dimConditions);
	}

	/* (non-Javadoc)
	 * @see nc.tb.analyse.ui.AbstractQueryDlg#configDimLayout(nc.tb.cube.CubeView)
	 */
	@Override
	protected void configDimLayout(CubeView cv) {
		if(cv != null && getCube() != null){
			DimDef[] dds = getCube().getSheetDef().getAllDimDefs();
			
			DimDef[] colDim = new DimDef[3];
			ArrayList<DimDef> rowDim = new ArrayList<DimDef>();
			ArrayList<DimDef> titleDim = new ArrayList<DimDef>();
			
			for(int i=0 ; i<dds.length ; i++){
				DimDef dd = dds[i];
				if(dd == null){
					continue;
				}
				if(dd.getType().equals(IDimType.YEAR)){
					colDim[0] = dd;
				}else if(dd.getType().equals(IDimType.MVTYPE)){
					colDim[1] = dd;
				}else if(dd.getType().equals(IDimType.ENTITY)){
					colDim[2] = dd;
				}else{
					if(getCube().getSheetDef().isParaDimDef(dd)){
						titleDim.add(dd);
					}else{
						if(isNullMember(dd)){
							titleDim.add(dd);
						}else{
							rowDim.add(dd);
						}
					}
				}
			}
			
			DimLayout dl = new DimLayout();
			dl.setColDimDefs(colDim);
			dl.setRowDimDefs(rowDim.toArray(new DimDef[0]));
			dl.setTitleDimDefs(titleDim.toArray(new DimDef[0]));
			
			cv.setDimLayout(dl);
		}
	}
	
	/* (non-Javadoc)
	 * @see nc.tb.analyse.ui.AbstractQueryDlg#configFml(nc.tb.cube.CubeView)
	 */
	@Override
	protected void configFml(CubeView cv) {

	}

}
